package io.huaguoguo.learn.service;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.huaguoguo.learn.entity.User;
import io.huaguoguo.learn.mapper.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author sundongkai 2021/1/12
 */
@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    @Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED)
    public void updateUser(User user) {
        this.updateById(user);

        User record = new User();
        record.setAge(666);
        record.setEmail(DateUtil.now());
        record.setName("修改了"+user.getId());
        this.save(record);
    }
}
